import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import { clearPending } from 'src/plugins/http/cancelToken';
import Home from '../views/Home.vue';

const routes: Array<RouteRecordRaw> = [
    {
        'path': '/',
        'name': 'Home',
        'component': Home,
        'redirect':'/login',
        'children': [
            {
                'path': '/login',
                'name': 'login',
                'meta': { 'title': '登录', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "login" */ '../views/login.vue')
            },
            {
                'path': '/userInfo',
                'name': 'userInfo',
                'redirect': '/myArticle',
                'meta': { 'title': '个人中心', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "userInfo" */ '../views/userInfo/index.vue'),
                'children': [
                    {
                        'path': '/myArticle',
                        'name': 'myArticle',
                        'meta': { 'title': '我的话题', 'keepAlive': true },
                        'component': () => import(/* webpackChunkName: "userInfo" */ '../views/userInfo/article/index.vue')
                    },
                    {
                        'path': '/myComment',
                        'name': 'myComment',
                        'meta': { 'title': '我的评论', 'keepAlive': true },
                        'component': () => import(/* webpackChunkName: "userInfo" */ '../views/userInfo/comment/index.vue')
                    },
                    {
                        'path': '/myReply',
                        'name': 'myReply',
                        'meta': { 'title': '我的回复', 'keepAlive': true },
                        'component': () => import(/* webpackChunkName: "userInfo" */ '../views/userInfo/reply/index.vue')
                    }
                ]
            },
            {
                'path': '/articleList/:code',
                'name': 'articleList',
                'meta': { 'title': '话题列表', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "article" */ '../views/article/list/index.vue')
            },
            {
                'path': '/articleDetail/:topicId',
                'name': 'articleDetail',
                'meta': { 'title': '话题详情', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "article" */ '../views/article/detail/index.vue')
            },
            {
                'path': '/articleSearch/:keyWords',
                'name': 'articleSearch',
                'meta': { 'title': '话题搜索', 'keepAlive': true },
                'component': () => import(/* webpackChunkName: "article" */ '../views/article/search/index.vue')
            }
        ]
    }
];

const router = createRouter({
    'history': createWebHashHistory(),
    routes
});

router.beforeEach((to, from) => {
    clearPending();
    return true;
});
router.afterEach((to, from) => true);

export default router;
